from fileinput import filename
from pathlib import Path
# 定义函数
def count_word(filename,word):
    """
    计算指定单词在文件中出现的次数
    :param filename: 要查找的文件名
    :param word: 要查找的单词
    :return: None
    """
    path = Path(filename)
    try:
        contents = path.read_text()
    except FileNotFoundError:
        print("未找到指定文件")
    else:
        word_count = contents.lower().count(word)
        print(f"{filename}文件中，单词{word}共出现了{word_count}次")

count_word("",'the')

